package com.xiao.framework.ds.autoconfigure.bean;

import com.xiao.framework.ds.autoconfigure.strategy.MultiDataSourceDetermineStrategy;
import java.util.LinkedList;
import java.util.List;
import javax.sql.DataSource;

/**
 * @author <a href="mailto:xiaoquanidea@163.com">hutiquan</a>
 * @since 2019-08-24 10:03
 */
public class GroupNameDataSource {

  private final MultiDataSourceDetermineStrategy multiDataSourceDetermineStrategy;
  private final String groupName;

  private final List<DataSource> groupDataSource = new LinkedList<>();

  public GroupNameDataSource(String groupName,MultiDataSourceDetermineStrategy multiDataSourceDetermineStrategy) {
    this.groupName = groupName;
    this.multiDataSourceDetermineStrategy = multiDataSourceDetermineStrategy;
  }

  public void addDataSource(DataSource dataSource){
    groupDataSource.add(dataSource);
  }

  public void removeDataSource(DataSource dataSource){
    groupDataSource.remove(dataSource);
  }

  public DataSource demeterDataSource(){
    return multiDataSourceDetermineStrategy.determineDataSource(groupDataSource);
  }
}
